package com.rental.houses.controller;


import com.rental.common.result.AjaxResult;
import com.rental.houses.service.IRentalHourseService;
import com.rental.model.entity.house.RentalHourse;
import com.rental.model.form.hourse.InsertRentalHourseForm;
import com.rental.model.form.hourse.RentalHourseForm;
import com.rental.model.vo.PageVo;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2025-01-16
 */
@RestController
@RequestMapping("/rental-hourse")
public class RentalHourseController {

    @Autowired
    private IRentalHourseService rentalHourseService;

    /**
     * 获取当前用户的所有出租房屋信息
     * @param uid
     * @return
     */
    @Operation(summary = "获取当前用户的所有出租房屋信息")
    @GetMapping("/getRentalHourseListByUid/{uid}")
    public AjaxResult<List<RentalHourse>> getRentalHourseListByUid(@PathVariable Long uid){
        return rentalHourseService.getRentalHourseListByUid(uid);
    }

    /**
     * 获取房屋列表
     * @return
     */
    @Operation(summary = "获取房屋列表")
    @GetMapping("/getRentalHourseList")
    public AjaxResult<List<RentalHourse>> getRentalHourseList(){
        return rentalHourseService.getRentalHourseList();
    }

    /**
     * 根据查询条件获取房屋列表
     * @param rentalHourseForm
     * @return
     */
    @Operation(summary = "根据查询条件获取房屋列表")
    @PostMapping("/getRentalHourseListBySearch")
    public AjaxResult<PageVo<RentalHourse>> getRentalHourseListBySearch(@RequestBody RentalHourseForm rentalHourseForm){
        return rentalHourseService.getRentalHourseListBySearch(rentalHourseForm);
    }

    /**
     * 房屋详情
     * @param id,uid  id:房屋id uid:房东id
     * @return
     */
    @Operation(summary = "房屋详情")
    @GetMapping("/getRentalHourseDetail/{id}/{uid}")
    public AjaxResult<RentalHourse> getRentalHourseDetail(@PathVariable Long id, @PathVariable Long uid){
        return rentalHourseService.getRentalHourseDetail(id,uid);
    }

    /**
     * 新增出租屋
     * @param insertRentalHourseForm
     * @return
     */
    @Operation(summary = "新增出租屋")
    @PostMapping("/insertRentalHourse")
    public AjaxResult<Boolean> insertRentalHourse(@RequestBody InsertRentalHourseForm insertRentalHourseForm){
        return rentalHourseService.insertRentalHourse(insertRentalHourseForm);
    }

    /**
     * 获取房东微信
     * @param id,uid  id:房屋id uid:房东id
     * @return
     */
    @Operation(summary = "获取房东微信")
    @GetMapping("/getLandlordWechat/{id}/{uid}")
    public AjaxResult<String> getLandlordWechat(@PathVariable Long id, @PathVariable Long uid){
        return rentalHourseService.getLandlordWechat(id,uid);
    }

    /**
     * 获取房东电话
     * @param id,uid  id:房屋id uid:房东id
     * @return
     */
    @Operation(summary = "获取房东电话")
    @GetMapping("/getLandlordPhone/{id}/{uid}")
    public AjaxResult<String> getLandlordPhone(@PathVariable Long id, @PathVariable Long uid){
        return rentalHourseService.getLandlordPhone(id,uid);
    }

    /**
     * 下架状态变更
     * @param id,uid  id:房屋id uid:房东id
     * @return
     */
    @Operation(summary = "下架状态变更")
    @GetMapping("/changeStatus/{id}/{uid}")
    public AjaxResult<Boolean> changeStatus(@PathVariable Long id, @PathVariable Long uid){
        return rentalHourseService.changeStatus(id,uid);
    }

    /**
     * 取消收藏出租屋
     * @param id,uid  id:房屋id uid:用户id，收藏者id
     * @return
     */
    @Operation(summary = "收藏出租屋")
    @GetMapping("/collectHouse/{id}/{uid}")
    public AjaxResult<Boolean> collectHouse(@PathVariable Long id, @PathVariable Long uid){
        return rentalHourseService.collectHouse(id,uid);
    }

    /**
     * 取消收藏出租屋
     * @param id,uid  id:房屋id uid:用户id，收藏者id
     * @return
     */
    @Operation(summary = "取消收藏出租屋")
    @GetMapping("/cancelCollectHouse/{id}/{uid}")
    public AjaxResult<Boolean> cancelCollectHouse(@PathVariable Long id, @PathVariable Long uid){
        return rentalHourseService.cancelCollectHouse(id,uid);
    }

    /**
     * 获取有效出租房源数
     * @return
     */
    @Operation(summary = "获取有效出租房源数")
    @GetMapping("/getValidRentalHourseCount")
    public AjaxResult<Long> getValidRentalHourseCount(){
        return rentalHourseService.getValidRentalHourseCount();
    }

    /**
     * 根据id获取出租房屋简介
     * @param id,state  id:房屋id state:状态
     * @return
     */
    @Operation(summary = "根据id获取出租房屋简介")
    @GetMapping("/getRentalHoursePage/{id}/{state}")
    public AjaxResult<RentalHourse> getRentalHoursePage(@PathVariable Long id, @PathVariable Integer state) {
        return rentalHourseService.getRentalHoursePage(id, state);
    }

    @Operation(summary = "举报")
    @GetMapping("/accusation/{id}")
    public AjaxResult<Boolean> accusation(@PathVariable Long id) {
        return rentalHourseService.accusation(id);
    }
}
